﻿using Basic.Core.Application.Services;
using System.Reflection;

namespace Basic.RPC;

/// <summary>
/// RPC服务端配置
/// </summary>
internal sealed class BasicRpcServerConfig
{
    /// <summary>
    /// 本地服务IP(不配置,则默认0.0.0.0)
    /// </summary>
    public string IP { get; set; }
    /// <summary>
    /// 本地Rpc监听端口
    /// </summary>
    public int RpcPort { get; set; }
}

internal class RpcClientService
{
    public string ServiceName { get; set; }
    public string AssemblyName { get; set; }
    public string[] RPCAddresses;

    private Type[] _interfaceTypes;
    /// <summary>
    /// Rpc接口类型集合
    /// </summary>
    public Type[] InterfaceTypes { get => _interfaceTypes ??= LoadRpcServiceType(); }

    private Type[] LoadRpcServiceType()
    {
        Type baseType = typeof(IApplicationService);
        var assembly = Assembly.Load(AssemblyName);
        return assembly.GetExportedTypes().Where(s => s.IsInterface && s.GetInterface(baseType.Name) != null).ToArray();
    }
}